var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  i = require("../../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../utils/tools/index"),
  s = require("../../../config/index"),
  u = require("../../../components/base/m-button/index"),
  d = e(require("./behavior"));

function o(e) {
  return c.apply(this, arguments)
}

function c() {
  return (c = n(r().mark((function e(t) {
    var n, a, s, u, d, o, c, l, m, p, h, f, _, v, b, g, y, q, x, T, w, k, C, V, X;
    return r().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.next = 2, $.request["GET/business/invoice/header/detail/".concat(t)]();
        case 2:
          n = e.sent, a = i(n, 1), 20002 === (s = a[0]).code && (this.selectComponent("#form").setValues({
                name:s.data.name,
                contactWay:s.data.contactWay,
                type:{
                  name:s.data.type==1?"个人":"企业",
                  id:s.data.type
                },
                isDefault:{
                  name:s.data.isDefault==1?"是":"否",
                  id:s.data.isDefault
                }
          }), this.setData({

          }));
        case 6:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}

function l(e, t) {
  return m.apply(this, arguments)
}

function m() {
  return (m = n(r().mark((function e(n, s) {
    var u, d, o, c, l;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return u = a.common.compactObj(n), d = s ? "POST/business/invoice/header/edit/" + n.uu : "POST/business/invoice/header/add", e.next = 4, $.request[d](t({}, u), {
            "content-type": "application/json"
          });
        case 4:
          o = e.sent, c = i(o, 1), l = c[0], 20002 == l.code ? ($.msg("添加成功"), setTimeout((function () {
            $.router.back({
              params: {
                "page-type": "publish"
              }
            })
          }), 2e3)) : $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: l.msg,
            cancelText: "知道了",
            confirmText: ""
          });
        case 9:
        case "end":
          return e.stop()
      }
    }), e)
  })))).apply(this, arguments)
}
Page({
  behaviors: [d.default],
  data: {
    mode: s.typeMode.device,
    recommendList: [],
    machineValue: null,
    useTypeList: [{
      id: 1,
      name: "出租"
    }, {
      id: 2,
      name: "出售"
    }, {
      id: 3,
      name: "出租/出售"
    }],
    useTypeValue: {
      id: 1,
      name: "出租"
    },
    date: '请选择日期',

    title: "",
    btn_txt: "立即添加",
    uu_id: "",
    statusList: [{
      id: 1,
      name: "个人"
    }, {
      id: 2,
      name: "企业"
    }],
    defaultList: [{
      id: 0,
      name: "否"
    }, {
      id: 1,
      name: "是"
    }],
    type: 1
  },
  bindDateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  onLoad: function (e) {
    this.selectComponent("#form").setValues({
      type: {
        id: 1,
        name: "个人"
      },
      isDefault: {
        id: 0,
        name: "否"
      }
    })
    if (e.uu_id) {
      this.setData({
        uu_id: e.uu_id,
        title: '修改发票抬头',
        btn_txt: "立即修改"
      })
    } else {
      this.setData({
        uu_id: e.uu_id,
        title: '添加发票抬头',
        btn_txt: "立即添加"
      })
    }

    o.call(this, e.uu_id)
  },
  onSubmit: (0, u.apply)(n(r().mark((function e() {
    var i, n, a, s, u, d, o, c, m, p, h, f, _, v;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return a = this.data, s = a.uu_id, u = a.mode, d = a.useTypeValue, e.next = 6, a.type == 1 ? this.selectComponent("#form").verify({
            type: [{
              required: !0,
              message: "请选择抬头类型"
            }],
            name: [{
              required: !0,
              message: "请填写单位名称"
            }],
            contactWay: [{
              required: !0,
              message: "请填写邮箱或者手机"
            }]
          }) : this.selectComponent("#form").verify({
            type: [{
              required: !0,
              message: "请选择抬头类型"
            }],
            name: [{
              required: !0,
              message: "请填写单位名称"
            }],
            contactWay: [{
              required: !0,
              message: "请填写邮箱或者手机"
            }],
            unifiedCreditCode: [{
              required: !0,
              message: "请填写纳税识别号"
            }]
          });
        case 6:
          if (o = e.sent, null != d && d.id) {
            e.next = 11;
            break
          }
          return e.abrupt("return", void $.msg("请选择机械用途"));
        case 9:
          if (o.detail && !((null === (i = o.detail) || void 0 === i ? void 0 : i.length) < 5)) {
            e.next = 11;
            break
          }
          return e.abrupt("return", void $.msg("设备简介必须大于5个字符"));
        case 11:
          c = o.address, m = o.machine, p = o.brand, h = o.model, f = o.images, _ = o.status, v = t(t({
            type: o.type.id || "",
            name: o.name || "",
            contactWay: o.contactWay,
            isDefault: o.isDefault.id,
            unifiedCreditCode:o.unifiedCreditCode||'',
            bankCode:o.bankCode||'',
            bankAccount:o.bankAccount||'',
            companyPhone:o.companyPhone||'',
            address:o.address||'',  
          }, c), {}, {

          }), s && (v.uu = s), l.call(this, v, s);
        case 13:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))),
  onClickUseType: function (e) {
    var t = e.target.dataset.item;
    this.setData({
      useTypeValue: {
        id: t.id,
        name: t.name
      }
    })
  }
});